package com.ruoyi.web.controller.emergency;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import com.ruoyi.common.helper.LoginHelper;
import lombok.RequiredArgsConstructor;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;

import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.vo.EmgTeamVo;
import com.ruoyi.system.domain.bo.EmgTeamBo;
import com.ruoyi.system.service.IEmgTeamService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 队伍团队
 *
 * @author ruoyi
 * @date 2023-11-10
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/emg/team")
public class EmgTeamController extends BaseController {

    private final IEmgTeamService iEmgTeamService;

    /**
     * 查询队伍团队列表
     */
    //@SaCheckPermission("emergency:team:list")
    @GetMapping("/list")
    public TableDataInfo<EmgTeamVo> list(EmgTeamBo bo, PageQuery pageQuery) {
        return iEmgTeamService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出队伍团队列表
     */
    //@SaCheckPermission("emergency:team:export")
    @Log(title = "队伍团队", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(EmgTeamBo bo, HttpServletResponse response) {
        List<EmgTeamVo> list = iEmgTeamService.queryList(bo);
        ExcelUtil.exportExcel(list, "队伍团队", EmgTeamVo.class, response);
    }

    /**
     * 获取队伍团队详细信息
     *
     * @param id 主键
     */
    //@SaCheckPermission("emergency:team:query")
    @GetMapping("/{id}")
    public R<EmgTeamVo> getInfo(@NotNull(message = "主键不能为空")
                                @PathVariable Long id) {
        return R.ok(iEmgTeamService.queryById(id));
    }

    /**
     * 新增队伍团队
     */
    //@SaCheckPermission("emergency:team:add")
    @Log(title = "队伍团队", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody EmgTeamBo bo) {
        bo.setDeptId(LoginHelper.getDeptId());
        return toAjax(iEmgTeamService.insertByBo(bo));
    }

    /**
     * 修改队伍团队
     */
    //@SaCheckPermission("emergency:team:edit")
    @Log(title = "队伍团队", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody EmgTeamBo bo) {
        return toAjax(iEmgTeamService.updateByBo(bo));
    }

    /**
     * 删除队伍团队
     *
     * @param ids 主键串
     */
    //@SaCheckPermission("emergency:team:remove")
    @Log(title = "队伍团队", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iEmgTeamService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
